[release/10.0] Fix alignment of 8-byte thread statics on direct TLS path#129785
Open
github-actions[bot] wants to merge 1 commit into
Open
[release/10.0] Fix alignment of 8-byte thread statics on direct TLS path#129785github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
GetTLSIndexForThreadStatic computes the alignment for a thread static placed on the direct-on-thread-local-data bump allocator. The chain of size checks was missing an `else` before the `>= 4` case, so an 8-byte field (long/double) first set alignment = 8 and then immediately overwrote it with alignment = 4. The resulting offset could land on a 4-mod-8 boundary, producing a misaligned long/double. On arm64 this causes Interlocked.Increment(ref threadStaticLong) to throw DataMisalignedException, since the atomic lowers to ldaxr/stlxr which fault on a misaligned address. Fixes #129733 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @agocke |
jkotas
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #129749 to release/10.0
/cc @EgorBo
Customer Impact
Some TLS (ThreadStatic) fields could be allocated with 4b alignment while demanding 8b e.g.
long. This may lead to DataMisalignedException in certain cases (e.g. using Interlocked on arm64, or double fields on arm32) or/and reiceve a perf penalty from misaligned access.Regression
It was introduced in .NET 9.0
Testing
Validated locally that 64-bit TLS variables never get any alignment less than 64 bytes.
Risk
Low to none.